﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace MoneyWentWhere.Utils
{
    public enum NumberSign { Negative, Zero, Positive }

    public static class ExtensionMethods
    {
        #region Numbers

        public static NumberSign Sign(this int x)
        {
            return x == 0 ? 0 :
                x > 0 ? NumberSign.Positive : NumberSign.Negative;
        }
        public static NumberSign Sign(this decimal x)
        {
            return x == 0 ? 0 :
                x > 0 ? NumberSign.Positive : NumberSign.Negative;
        }

        #endregion

        #region LINQ-like

        /// <summary>
        /// Execute for each element (immediately). 
        /// Sometimes more convenient than a foreach loop syntax. 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="en"></param>
        /// <param name="action"></param>
        public static void ForEach<T>(this IEnumerable<T> en, Action<T> action)
        {
            foreach (T x in en) { action(x); }
        }

        #endregion

        #region Argument Validation

        /// <summary>
        /// Throw an ArgumentNullException if argument is null.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <param name="argName"></param>
        [DebuggerHidden]
        public static void ArgNotNull<T>(this T obj, String argName) where T : class
        {
            if (obj == null) { throw new ArgumentNullException(argName); }
        }

        public static void ArgNotNullOrEmpty(this string obj, string argName)
        {
            if (String.IsNullOrEmpty(obj)) { throw new ArgumentException(argName); }
        }

        #endregion



    }
}
